class Solution {
public:
    int findLongestChain(vector<vector<int>>& a) {
        int n = a.size();
        sort(a.begin(), a.end());
        vector<int>f(n, 1);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (a[i][0] > a[j][1]) {
                    f[i] = max(f[j] + 1, f[i]);
                }
            }
        }
        return f[n - 1];
    }
};